from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-27 14:02:22.522017
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 27, Apr, 2022
Time: 14:02:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0927
Nobs: 639.000 HQIC: -49.4770
Log likelihood: 7815.50 FPE: 2.54984e-22
AIC: -49.7209 Det(Omega_mle): 2.21727e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.328521 0.062201 5.282 0.000
L1.Burgenland 0.104826 0.039450 2.657 0.008
L1.Kärnten -0.110122 0.020682 -5.324 0.000
L1.Niederösterreich 0.196518 0.082473 2.383 0.017
L1.Oberösterreich 0.119421 0.081356 1.468 0.142
L1.Salzburg 0.258482 0.041904 6.168 0.000
L1.Steiermark 0.043645 0.055110 0.792 0.428
L1.Tirol 0.104039 0.044566 2.334 0.020
L1.Vorarlberg -0.064970 0.039350 -1.651 0.099
L1.Wien 0.025724 0.072125 0.357 0.721
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051960 0.132933 0.391 0.696
L1.Burgenland -0.035045 0.084311 -0.416 0.678
L1.Kärnten 0.041235 0.044202 0.933 0.351
L1.Niederösterreich -0.196151 0.176258 -1.113 0.266
L1.Oberösterreich 0.451927 0.173871 2.599 0.009
L1.Salzburg 0.285367 0.089555 3.186 0.001
L1.Steiermark 0.107843 0.117779 0.916 0.360
L1.Tirol 0.309063 0.095245 3.245 0.001
L1.Vorarlberg 0.023885 0.084097 0.284 0.776
L1.Wien -0.031448 0.154144 -0.204 0.838
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189789 0.031829 5.963 0.000
L1.Burgenland 0.089995 0.020187 4.458 0.000
L1.Kärnten -0.007625 0.010584 -0.720 0.471
L1.Niederösterreich 0.247115 0.042203 5.855 0.000
L1.Oberösterreich 0.158767 0.041631 3.814 0.000
L1.Salzburg 0.040494 0.021443 1.888 0.059
L1.Steiermark 0.026169 0.028201 0.928 0.353
L1.Tirol 0.085104 0.022805 3.732 0.000
L1.Vorarlberg 0.054092 0.020136 2.686 0.007
L1.Wien 0.117614 0.036908 3.187 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111205 0.031919 3.484 0.000
L1.Burgenland 0.044589 0.020244 2.203 0.028
L1.Kärnten -0.013778 0.010613 -1.298 0.194
L1.Niederösterreich 0.177432 0.042322 4.192 0.000
L1.Oberösterreich 0.330285 0.041749 7.911 0.000
L1.Salzburg 0.101423 0.021503 4.717 0.000
L1.Steiermark 0.111735 0.028280 3.951 0.000
L1.Tirol 0.094703 0.022870 4.141 0.000
L1.Vorarlberg 0.059784 0.020193 2.961 0.003
L1.Wien -0.018064 0.037012 -0.488 0.626
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.113416 0.059595 1.903 0.057
L1.Burgenland -0.044061 0.037798 -1.166 0.244
L1.Kärnten -0.045463 0.019816 -2.294 0.022
L1.Niederösterreich 0.142262 0.079018 1.800 0.072
L1.Oberösterreich 0.159467 0.077948 2.046 0.041
L1.Salzburg 0.283458 0.040148 7.060 0.000
L1.Steiermark 0.056964 0.052802 1.079 0.281
L1.Tirol 0.162108 0.042699 3.796 0.000
L1.Vorarlberg 0.097348 0.037702 2.582 0.010
L1.Wien 0.076766 0.069104 1.111 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059558 0.046844 1.271 0.204
L1.Burgenland 0.029187 0.029711 0.982 0.326
L1.Kärnten 0.052173 0.015576 3.349 0.001
L1.Niederösterreich 0.202219 0.062112 3.256 0.001
L1.Oberösterreich 0.326279 0.061271 5.325 0.000
L1.Salzburg 0.037978 0.031558 1.203 0.229
L1.Steiermark 0.008525 0.041504 0.205 0.837
L1.Tirol 0.126557 0.033564 3.771 0.000
L1.Vorarlberg 0.064289 0.029635 2.169 0.030
L1.Wien 0.094221 0.054319 1.735 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172136 0.056341 3.055 0.002
L1.Burgenland 0.005693 0.035734 0.159 0.873
L1.Kärnten -0.064910 0.018734 -3.465 0.001
L1.Niederösterreich -0.097713 0.074704 -1.308 0.191
L1.Oberösterreich 0.204197 0.073692 2.771 0.006
L1.Salzburg 0.055055 0.037956 1.450 0.147
L1.Steiermark 0.240060 0.049919 4.809 0.000
L1.Tirol 0.500765 0.040368 12.405 0.000
L1.Vorarlberg 0.062022 0.035643 1.740 0.082
L1.Wien -0.074916 0.065331 -1.147 0.252
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146138 0.062274 2.347 0.019
L1.Burgenland 0.002451 0.039496 0.062 0.951
L1.Kärnten 0.061715 0.020707 2.980 0.003
L1.Niederösterreich 0.177899 0.082570 2.155 0.031
L1.Oberösterreich -0.056654 0.081451 -0.696 0.487
L1.Salzburg 0.207665 0.041953 4.950 0.000
L1.Steiermark 0.136831 0.055175 2.480 0.013
L1.Tirol 0.061806 0.044619 1.385 0.166
L1.Vorarlberg 0.146350 0.039396 3.715 0.000
L1.Wien 0.117873 0.072210 1.632 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377620 0.036706 10.288 0.000
L1.Burgenland -0.001997 0.023281 -0.086 0.932
L1.Kärnten -0.021337 0.012205 -1.748 0.080
L1.Niederösterreich 0.208907 0.048670 4.292 0.000
L1.Oberösterreich 0.228782 0.048010 4.765 0.000
L1.Salzburg 0.038646 0.024729 1.563 0.118
L1.Steiermark -0.012626 0.032522 -0.388 0.698
L1.Tirol 0.091962 0.026300 3.497 0.000
L1.Vorarlberg 0.052721 0.023222 2.270 0.023
L1.Wien 0.039596 0.042563 0.930 0.352
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036071 0.113173 0.173075 0.141176 0.101911 0.085963 0.037311 0.209178
Kärnten 0.036071 1.000000 -0.022569 0.132522 0.051489 0.088448 0.441934 -0.063601 0.090906
Niederösterreich 0.113173 -0.022569 1.000000 0.320712 0.128755 0.282056 0.075357 0.159602 0.294678
Oberösterreich 0.173075 0.132522 0.320712 1.000000 0.219698 0.306564 0.168961 0.144374 0.245359
Salzburg 0.141176 0.051489 0.128755 0.219698 1.000000 0.130057 0.098295 0.110133 0.127445
Steiermark 0.101911 0.088448 0.282056 0.306564 0.130057 1.000000 0.139875 0.116116 0.044862
Tirol 0.085963 0.441934 0.075357 0.168961 0.098295 0.139875 1.000000 0.069233 0.149586
Vorarlberg 0.037311 -0.063601 0.159602 0.144374 0.110133 0.116116 0.069233 1.000000 0.000796
Wien 0.209178 0.090906 0.294678 0.245359 0.127445 0.044862 0.149586 0.000796 1.000000